﻿using System.IO;
using weka.core;

namespace MLSharp.Weka
{
	/// <summary>
	/// Provides methods for saving datasets to files.
	/// </summary>
	public static class DataSetSaver
	{
		/// <summary>
		/// Creates a Weka ARFF file from the specified dataset.
		/// </summary>
		/// <param name="dataSet">The dataset.</param>
		/// <param name="filename">Where to save the data to.</param>
		/// <remarks>
		/// If the specified file exists, it is overwritten.
		/// </remarks>
		public static void SaveArff(IDataSet dataSet, string filename)
		{
			Instances instances = dataSet.ToInstances();

			using (StreamWriter writer = File.CreateText(filename))
			{
				//toString returns the data in ARFF format.
				writer.Write(instances.toString());
			}
		}
	}
}
